package com.jcnet.bizaia;
import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.MenuItem;
import com.jcnet.bizaia.adapter.MainMenuAdapter;
import com.jcnet.bizaia.fragment.DiscussionInfoFragment;
import com.jcnet.bizaia.fragment.FavouriteDiscountFragment;
import com.jcnet.bizaia.fragment.FavouriteVodFragment;
import com.jcnet.bizaia.fragment.FavouriteVoiceFragment;
import com.jcnet.bizaia.fragment.SettingTalkVodFragment;
import com.jcnet.bizaia.fragment.SettingTalkVoiceFragment;
import com.jcnet.bizaia.fragment.VodInfoFragment;
import com.jcnet.bizaia.fragment.VoiceInfoFragment;
import com.viewpagerindicator.IconPagerAdapter;
import com.viewpagerindicator.TabPageIndicator;

public class SettingTalkActivity  extends JCSimpleSherlockActivity implements OnClickListener{
	
	public static final int DISCUSS_ID = 1;
	public static final int VOD_ID = 2;
	public static final int VOICE_ID = 3;
	
	private TabPageIndicator indicator;
	
	private ViewPager viewPager;
	
	private String [] mainTitles; 
	
	
	private List<Fragment> fragments;
	
	
	
	private boolean isShowMenu = false;

	
	private int pageNow = 0;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.favourite);
		super.jcTitle = getString(R.string.setting);
		super.jcSubtitle =getString(R.string.myTalk);
		super.initActionBar();
		mainTitles = getResources().getStringArray(R.array.setting_category);
		initView();
	}



	private void initView() {
		// TODO Auto-generated method stub
		initData();
		
		
		
		indicator = (TabPageIndicator)findViewById(R.id.indicator);
		viewPager = (ViewPager)findViewById(R.id.pager);
		viewPager.setAdapter(new GoogleMusicAdapter(getSupportFragmentManager()));
		viewPager.setOffscreenPageLimit(mainTitles.length);
		viewPager.setCurrentItem(0);
		indicator.setViewPager(viewPager);
		
		indicator.setOnPageChangeListener(new OnPageChangeListener() {
			
			@Override
			public void onPageSelected(int arg0) {
				// TODO Auto-generated method stub
				System.out.println("onPageSelected______________________"+arg0);
				pageNow = arg0;
			}
			
			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onPageScrollStateChanged(int arg0) {
				// TODO Auto-generated method stub
				
			}
		});
		
	}

	private void initData() {
		// TODO Auto-generated method stub
		fragments = new ArrayList<Fragment>();
		fragments.add(SettingTalkVodFragment.newInstance());
		fragments.add(SettingTalkVoiceFragment.newInstance());
	}

	@Override
	public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
		// TODO Auto-generated method stub
		return super.onCreateOptionsMenu(menu);
	}
	
	
	   class GoogleMusicAdapter extends FragmentPagerAdapter implements IconPagerAdapter {
	        public GoogleMusicAdapter(FragmentManager fm) {
	            super(fm);
	        }

	        @Override
	        public Fragment getItem(int position) {
	        	
	        	return fragments.get(position);
	            //return TestFragment.newInstance(CONTENT[position % CONTENT.length]);
	        }

	        @Override
	        public CharSequence getPageTitle(int position) {
	            return mainTitles[position];
	        }

	        @Override public int getIconResId(int index) {
	          return 0;
	        }

	      @Override
	        public int getCount() {
	          return mainTitles.length;
	        }
	    }
	

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.searchButton:
			
			switch (pageNow) {
			case 0:
				startActivity(new Intent(SettingTalkActivity.this, DiscussSearchActivity.class));
				break;
			case 1:
				startActivity(new Intent(SettingTalkActivity.this, VodSearchActivity.class));
				break;
				
			default:
				break;
			}
			
			break;

		default:
			break;
		}
	}


	
}
